<?php

require_once('../../includes/classes/core.php');
$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

switch ($action) {
	case 'get_list' :
		$count = 		$_REQUEST['count'];
		$hidden = 		$_REQUEST['hidden'];
		$start		= $_REQUEST['start'];
		$end		= $_REQUEST['end'];
	  	$rResult = mysql_query("SELECT  calldate, 
	  	                                calldate,
                                        src, 
                                        dst, 
                                        SEC_TO_TIME(duration-billsec) AS `wait`, 
                                        SEC_TO_TIME(billsec),
                                        CONCAT('<button style=\"width:100%; margin:5px 0;\" class=\"lisen ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover\" onclick=\"play(\'',SUBSTR(userfield,7),'\')\" ><span class=\"ui-button-text\">მოსმენა</span></button>') AS `rec`
                                FROM cdr
                                WHERE DATE(calldate) >='$start'
	  	                        AND DATE(calldate) <='$end'
                                AND LENGTH(src) < 7
                                AND LENGTH(dst) < 7
                                AND lastapp != 'Queue'
                                AND disposition = 'ANSWERED'
                                AND SUBSTR(dstchannel,1,5) != 'Local'");
	  
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
			}
			$data['aaData'][] = $row;
		}

		break;
		
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);

?>